package com.sky.web.app;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    ShoppingCartService shoppingCartService;

    /**
     * 购物车列表查询
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        List<ShoppingCart> list = shoppingCartService.list();
        return Result.success(list);
    }

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 清除购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result clean(){
       shoppingCartService.clear();
            return Result.success();

    }

    /**
     * 减少菜品数量
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    public Result subtraction(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.subtraction(shoppingCartDTO);
        return Result.success();
    }
}

